<form id="dorefund" class="tableform" method='post' action='index.php?ctl=admin_refund_apply&app=ome&act=accept&p[0]=<{$refund.apply_id}>&finder_id=<{$env.get.finder_id}>&source=<{$refund.source}>'>
<input type='hidden' name='api_fail_flag' id='api_fail_flag' value='<{$api_fail_flag}>' />
<input type='hidden' name='return_id' id='return_id' value='<{$return_id}>' />
<input type='hidden' name='api_refund_request' id='api_refund_request' value='false' />
<input type='hidden' name='shop_id' id='shop_id' value='<{$shop_id}>'>
<input type='hidden' name='order_id' id='order_id' value='<{$order.order_id}>'>

  <div class="division">
    <table width="100%" cellspacing="0" cellpadding="0" border="0">
      <tr>
        <th><{t}>平台订单号:<{/t}></th>
        <td><{$order.order_bn}> 【<{$pay_status[$order.pay_status];}>】</td>
        <th><{t}>下单日期:<{/t}></th>
        <td><{$order.createtime|cdate:'SDATE_STIME'}></td>
      </tr>
      <tr>
        <th><{t}>订单金额:<{/t}></th>
        <td><{$order['total_amount']}></td>

        <th><{t}>已付金额:<{/t}></th>
        <td><{$order.payed}></td>
      </tr>
      <tr>
        <th><{t}>退款类型: <{/t}></th>
        <td>              
            <{foreach from=$typeList key=key item=item}>
                <input type="radio" name="pay_type"  value=<{$key}> vtype='requiredradio'><lable><{$item}></lable>&nbsp;
            <{/foreach}>
        </td>
        <th><{t}>退款支付方式:<{/t}></th>
        <td>
        <{if $payment}>
            <{if $node_id}>
                <select id='payment' name='payment'>
                    <{if $payment_id}>
                      <{foreach from=$order_paymentcfg key=key item=item}>
                        <option value="<{$item.id}>"><{$item.custom_name}></option>
                      <{/foreach}>
                    <{/if}>
                </select>
            <{else}>
                <{input type="select" id="payment" name='payment' rows=$payment valueColumn="id" labelColumn="custom_name" value=$payment_id }>
            <{/if}>
        <{else}>
        <select id='payment' name='payment'>
        </select>
        <em class="red">请先添加或同步前端店铺支付方式</em>
        <{/if}>
        </td>
      </tr>
      <tr>
        <th><{t}>退款银行:<{/t}></th>
        <td colspan="3"><{input type='text' id='payBank' name='bank' value=$refund.bank width="140"}> <{input id="selectAccount" type="select" name='select_account' options=$pay_account  value=''}></td>
      </tr>
      <tr>
        <th><{t}>退款帐号:<{/t}></th>
        <td><{input type='text' name='account' id='payAccount' value=$refund.account width="140"}></td>
        <th><{t}>收款帐号:<{/t}></th>
        <td><{input type='text' name='pay_account' value=$refund.pay_account width="80"}></td>
      </tr>
      <tr>
        <th><{t}>退款金额:<{/t}></th>
        <td><{$refund.money}><{input type='hidden' id='money' name='money' value=$refund.money width="140"}></td>
        <th><{t}>补偿金额:<{/t}></th>
        <td><{$refund.bcmoney}></td>
      </tr>
      <tr>
        <th><{t}>第三方交易号:<{/t}></th>
        <td><{input type='text' id='trade_no' name='trade_no'  width="140"}></td>
      </tr>
    </table>
  </div>
  <div class="table-action">
    <{if $api_fail_flag eq 'true' || ($order.pay_status eq  '7' && $api_fail_flag eq 'false' ) }><!--因为退款失败-->
        <{button type="button" label="仅本地退款" class="btn-primary" id="submit_btn_local"}>
        <{button type="button" label="本地退款并发送同步请求" class="btn-primary" id="submit_btn_remote"}>
    <{else}>
        <{button type="button" label="提交" class="btn-primary" id="submit_btn"}>
    <{/if}>
  </div>
</form>

<script>

$$('input[name^=pay_type]').addEvent('click', function(){
    var order_id = $('order_id').value, shop_id = $('shop_id').value, pay_type = this.value;
    W.page('index.php?app=ome&ctl=admin_finance&act=payment_by_pay_type&p[0]='+order_id+'&p[1]='+shop_id+'&p[2]='+pay_type,{update:$('payment'),onComplete:function(){
        if($('payment').length <= 1){
            $('payment').disabled = 'disabled';
        }
    }});
});

if ($('submit_btn_local')){
    $('submit_btn_local').addEvent('click',function (){
        $('api_refund_request').set('value', 'false');
        $('submit_btn_remote').set('disabled', 'true');
        $('dorefund').fireEvent('submit',{stop:function(){}});
    });
}

if ($('submit_btn_remote')){
    $('submit_btn_remote').addEvent('click',function (){
        $('api_refund_request').set('value', 'true');
        $('submit_btn_local').set('disabled', 'true');
        $('dorefund').fireEvent('submit',{stop:function(){}});
    });
}

if ($('submit_btn')){
    $('submit_btn').addEvent('click',function (){
        $('api_refund_request').set('value', 'true');
        $('dorefund').fireEvent('submit',{stop:function(){}});
    });
}

$('selectAccount').addEvent('change', function(e){
    e=new Event(e);
    var ipt=e.target;
    var str = ipt.value;
    var aItems = str.split('-');
    $('payBank').value = aItems[0];
    $('payAccount').value = aItems[1];
});

$('dorefund').store('target',{
    onRequest:function(){
      if ($('submit_btn')){
        $('submit_btn').set('disabled', 'true');
        $('submit_btn').getElements('span')[1].set('text','正在提交');
      }else{
        $('submit_btn_local').set('disabled', 'true');
        $('submit_btn_remote').set('disabled', 'true');
      }

    },
    onComplete:function(jsontext){
      //jsontext = jsontext.replace(/[\r\n]+/img, ' ');
      var json = Json.evaluate(jsontext);
      if (typeof(json.error) == 'undefined'){
        if (typeof(json.error) == 'undefined'){
          $('dorefund').getParent('.dialog').retrieve('instance').close();
          parent.finderGroup['<{$finder_id}>'].refresh.delay(400,parent.finderGroup['<{$finder_id}>']);
        }
      }else{
        if ($('submit_btn')){
            $('submit_btn').set('disabled', '');
            $('submit_btn').getElements('span')[1].set('text','提交');
        }else{
            $('submit_btn_local').set('disabled', '');
            $('submit_btn_remote').set('disabled', '');        
        }
      }
    }
});
</script>
